package com.aacar.utils;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class StringUtils {
	private static Log logger = LogFactory.getLog(StringUtils.class);
	
	/**
	 * 去除左补0
	 * @param value
	 * @return
	 */
	public static String delLeftFix0(String value){
		String newStr = value.replaceFirst("^0*", "");
		return newStr;
	}
	
	/**
	 * 字符串补齐
	 * @param source 源字符串
	 * @param fillLength 补齐长度
	 * @param fillChar 补齐的字符
	 * @param isLeftFill true为左补齐，false为右补齐
	 * @return
	 */
	public static String stringFill(String source, int fillLength, char fillChar, boolean isLeftFill) {
	    if (source == null || source.length() >= fillLength) return source;
	     
	    StringBuilder result = new StringBuilder(fillLength);
	    int len = fillLength - source.length();
	    if (isLeftFill) {
	        for (; len > 0; len--) {
	            result.append(fillChar);
	        }
	        result.append(source);
	    } else {
	        result.append(source);
	        for (; len > 0; len--) {
	            result.append(fillChar);
	        }
	    }
	    return result.toString();
	}
}
